/**
 * Created by baoman on 2017/3/29.
 */
angular.module('elife.controllers')
  .controller('CalendarCtrl', function($scope,$state,CustomerListService) {
    var calendar = this;
    var tempDate = new Date();

    calendar.flag = true;

    calendar.changeDay = changeDay;

    calendar.sortType = 0;
    calendar.productType = 0;
    calendar.selectTask = CustomerListService.chooseTask(formatDate(new Date()));
    calendar.tasks = CustomerListService.customerList();
    calendar.dateTaskList = [];

    calendar.sortData=[
      {
        value:0,
        text:'全部状态'
      },
      {
        value:1,
        text:'保险培训'
      },
      {
        value:2,
        text:'了解客户'
      }
    ];

    calendar. productData=[
      {
        value:0,
        text:'筛选'
      },
      {
        value:1,
        text:'有进展'
      },
      {
        value:2,
        text:'无进展'
      }
    ];

    init();

    function init () {
      var tempData = []
      for ( var i = 0; i < calendar.tasks.length; i++) {
        tempData.push(calendar.tasks[i].date);
      }
      calendar.dateTaskList = tempData;
    }

    function changeDay (date) {
      calendar.selectTask = CustomerListService.chooseTask(formatCalenar(date));
    }

    function formatDate (date) {
      var strDate = date.getFullYear();
      if(date.getMonth() + 1 < 10){
        strDate += '-0' + (date.getMonth()+1);
      } else{
        strDate += '-' + (date.getMonth()+1);
      }
      if(date.getDate() < 10){
        strDate += '-0' + date.getDate();
      } else {
        strDate += '-' + date.getDate();
      }
      return strDate;
    }

    function formatCalenar (date) {
      var strDate = date.solarYear;
      if(date.solarMonth < 10){
        strDate += '-0' + date.solarMonth;
      } else{
        strDate += '-' + date.solarMonth;
      }
      if(date.solarDate < 10){
        strDate += '-0' + date.solarDate;
      } else {
        strDate += '-' + date.solarDate;
      }
      return strDate;
    }
  });